package com.photoeditor.demo.util;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.common.base.log.RLog;
import com.common.base.utils.SystemUtils;
import com.photoeditor.R;

/**
 * Created by mutour on 2017/1/17.
 */

public class Feedback {
    private static String TAG = "Feedback";

    private static String SEND_TO = "@gmail.com";

    static class UserInfo {
        String androidId;
        String country;
        String language;
        String model;
        String brand;
        String os;
        String imei;
        int versionCode;
        String versionName;
        private static UserInfo mUserInfo;
        private UserInfo(Context context) {
            androidId = SystemUtils.getAndroidId(context);
            country = SystemUtils.getCountry(context);
            language = ProtocolUtil.getLanguage(context);
            model = ProtocolUtil.getModel();
            os = ProtocolUtil.getOS();
            brand = ProtocolUtil.getBrand();
            imei = ProtocolUtil.getVirtualIMEI(context);
            versionCode = com.common.base.utils.AppUtils.getVersionCode(context);
            versionName = com.common.base.utils.AppUtils.getVersionName(context);
        }
        public static UserInfo getUserInfo(Context context) {
            if(mUserInfo == null) {
                mUserInfo = new UserInfo(context);
            }
            return mUserInfo;
        }

        @Override
        public String toString() {
            return  "Country: " + country + "\n" +
                    "Brand: " + brand + "\n" +
                    "Model: " + model + "\n" +
                    "Version: " + versionCode + "\n" +
//                    "Region:" + country + "\n" +
                    "Locale: " + language + "\n" +
                    "Android version: " + os;
        }
    }



    /**
     * 意见反馈入口，点击后，直接调起Gmail，
     * 通过Gmail的形式进行反馈，需将用户的基本附在邮件中（国家、机型、版本号、地区、语言、android版本）
     */
    public static void feedback(Context context) {
        UserInfo userInfo = UserInfo.getUserInfo(context);
        String info = userInfo.toString();
        RLog.d(TAG, info);

        /**
         	意见反馈入口，点击后，直接调起Gmail，通过Gmail的形式进行反馈
         	邮箱：beyondgreatapp@gmail.com
         	标题：Feedback for POTD Camera
         	附带信息
         	Country: XXX
         	Brand: XXX
         	Model: XXX
         	Version: XXX
         	Locale: XXX
         	Android version: XXX

         */

        String title = context.getString(R.string.feedback_for_photo_editor);
        String feedbackContent = "\n\n\n\n\n\n\n\n"+info;
        String email = "mailto:" + SEND_TO;

        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setType("message/rfc822");
        emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        emailIntent.putExtra(Intent.EXTRA_TEXT, feedbackContent);
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, title);
        Uri uri = Uri.parse(email);
//        String infoFileName = BaseInfoSaver.getInstanceSingleton().getInfoFileName();
//        if (infoFileName != null && !TextUtils.isEmpty(infoFileName)) {
//            emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(infoFileName)));
//        }
        emailIntent.setAction(Intent.ACTION_SENDTO);
        emailIntent.setData(uri);

        try {
            context.startActivity(emailIntent);
        } catch (Exception ex) {
            ex.printStackTrace();
        }


    }

}
